
import React from 'react'

const { Provider, Consumer: MapConsumer } = React.createContext();

class MapProvider extends React.Component {

  constructor() {
    super();
    let tmp = localStorage.getItem('showMap')? JSON.parse(localStorage.getItem('showMap')) : true
    this.state = {
      showMap:tmp
    }
  }

  changeMap() {
    this.setState({
      showMap: !this.state.showMap
    },()=>{
      localStorage.setItem('showMap',this.state.showMap)
    })
  }

  render() {
    return (
      <Provider value={{
        showMap: this.state.showMap,
        changeMap: () => this.changeMap()
      }}>
        {this.props.children}
      </Provider>
    )
  }
}

export {
  MapConsumer,
  MapProvider
}